package com.rayboo.example.random;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class GenNumber extends Thread {

    public static void main(String[] args) {
        GenNumber c = new GenNumber();
        c.start();

        GenNumber c1 = new GenNumber();
        c1.start();
    }

    @Override
    public void run() {
        long start = System.currentTimeMillis();
        List<String> list = genNumber(10000);
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        System.out.println("size" + list.size());
        System.out.println(list.toString());
    }

    public static String getGuid() {

        int guid = 101;

        long now = System.currentTimeMillis();
        //获取4位年份数字
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
        //获取时间戳
        String time = dateFormat.format(now);
        String info = now + "";
        //获取三位随机数
        //int ran=(int) ((Math.random()*9+1)*100);
        //要是一段时间内的数据连过大会有重复的情况，所以做以下修改
        int ran = 0;
        if (guid > 999) {
            guid = 100;
        }
        ran = guid;

        return time + info.substring(2, info.length()) + ran;
    }

    public static List<String> genNumber(int loopNumber) {
        List<String> list = new ArrayList<String>();
        String[] ch = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
                "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
                "X", "Y", "Z"};

        int number = 1000000;
        int c = 0;
        String sb = null;
        for (int i = 0; i < loopNumber; i++) {
            sb = ch[c] + number;
            if (sb.length() > 9) {//如果字母后面满了，就换下一个字母组合，再把字母后面的值全部归零
                c++;
                number = 1000000;
            }
            list.add(ch[c] + number);
            number++;
        }
        return list;
    }

}
